//
//  StatusBar-Extension.swift
//  CustomStatusBarDemo
//
//  Created by 李煜 on 2024/1/12.
//

import UIKit

extension UIViewController {
    func statusBarColorChange() {
        if #available(iOS 13.0, *) {
            let rect = UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame
            let statusBar = UIView(frame: rect ?? CGRect.zero)
            statusBar.backgroundColor = .appNavigationThemeColor
            statusBar.tag = 100
            UIApplication.shared.windows.filter { $0.isKeyWindow }.first?.addSubview(statusBar)

        } else {
            let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView
            statusBar?.backgroundColor = .appNavigationThemeColor
        }
    }
}

extension UIColor {
    static var appNavigationThemeColor: UIColor {
        UIColor.systemPink
    }
}
